home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 September / PCgo 2008-09 (DVD).iso / interface / js / search.js < prev    next >
Encoding:
JavaScript  |  2008-07-13  |  35.5 KB  |  1,206 lines

  1. // ********************************************************************************************************************
  2. // Search Functions
  3. // ********************************************************************************************************************
  4.  
  5. var globalHightLightColor = "";
  6. var globalHightLightColorCell1 = '';
  7. var globalHightLightColorCell2 = '';
  8. var globalHightLightColorCell3 = '';
  9.  
  10. function issueItem() {
  11.   var year;
  12.   var nos = new Array();
  13. }
  14.  
  15. function nodeResultItem() {
  16.   var year = '';
  17.   var nr = '';
  18.   var category = '';
  19.   var title = '';
  20.   var description = '';
  21.   var link = '';
  22. }
  23.  
  24. var smallLetters = 'abcdefghijklmnopqrstuvwxyz';
  25. var bigLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  26. var xmlDocLocal = null;
  27. var xmlDocGlobal = null;
  28. var availableCategories = new Array();
  29. var availableIssues = new Array();
  30. var sorting = 1;
  31. var globalResultNodes = null;
  32. var localResultNodes = null;
  33.  
  34. function sortByTitleDESC (a, b) {
  35.   var valueA = a.title.toLowerCase();
  36.   var valueB = b.title.toLowerCase();
  37.   return ((valueA < valueB) ? -1 : ((valueA > valueB) ? 1 : 0));
  38. }
  39.  
  40. function sortByTitleASC (a, b) {
  41.   var valueA = a.title.toLowerCase();
  42.   var valueB = b.title.toLowerCase();
  43.   return ((valueA < valueB) ? 1 : ((valueA > valueB) ? -1 : 0));
  44. }
  45.  
  46. function sortByCategoryDESC (a, b) {
  47.   var valueA = a.category.toLowerCase();
  48.   var valueB = b.category.toLowerCase();
  49.   return ((valueA < valueB) ? -1 : ((valueA > valueB) ? 1 : 0));
  50. }
  51.  
  52. function sortByCategoryASC (a, b) {
  53.   var valueA = a.category.toLowerCase();
  54.   var valueB = b.category.toLowerCase();
  55.   return ((valueA < valueB) ? 1 : ((valueA > valueB) ? -1 : 0));
  56. }
  57.  
  58. function sortByDescriptionDESC (a, b) {
  59.   var valueA = a.description.toLowerCase();
  60.   var valueB = b.description.toLowerCase();
  61.   return ((valueA < valueB) ? -1 : ((valueA > valueB) ? 1 : 0));
  62. }
  63.  
  64. function sortByDescriptionASC (a, b) {
  65.   var valueA = a.description.toLowerCase();
  66.   var valueB = b.description.toLowerCase();
  67.   return ((valueA < valueB) ? 1 : ((valueA > valueB) ? -1 : 0));
  68. }
  69.  
  70. function sortByIssueDESC (a, b) {
  71.   var yearA = parseInt(a.year);
  72.   var yearB = parseInt(b.year);
  73.   var nrA = parseInt(a.nr);
  74.   var nrB = parseInt(b.nr);
  75.   if (yearA == yearB) {
  76.     return ((nrA > nrB) ? 1 : ((nrA < nrB) ? -1 : 0));
  77.   }
  78.   else {
  79.     return ((yearA > yearB) ? 1 : ((yearA < yearB) ? -1 : 0));
  80.   }
  81. }
  82.  
  83. function sortByIssueASC (a, b) {
  84.   var yearA = parseInt(a.year);
  85.   var yearB = parseInt(b.year);
  86.   var nrA = parseInt(a.nr);
  87.   var nrB = parseInt(b.nr);
  88.   if (yearA == yearB) {
  89.     return ((nrA < nrB) ? 1 : ((nrA > nrB) ? -1 : 0));
  90.   }
  91.   else {
  92.     return ((yearA < yearB) ? 1 : ((yearA > yearB) ? -1 : 0));
  93.   }
  94. }
  95.  
  96. function doSort(nodesArray) {
  97.     switch (sorting) {
  98.       case 1:
  99.         nodesArray.sort(sortByTitleDESC);
  100.         break;
  101.       case 2:
  102.         nodesArray.sort(sortByTitleASC);
  103.         break;
  104.       case 3:
  105.         nodesArray.sort(sortByCategoryDESC);
  106.         break;
  107.       case 4:
  108.         nodesArray.sort(sortByCategoryASC);
  109.         break;
  110.       case 5:
  111.         nodesArray.sort(sortByDescriptionDESC);
  112.         break;
  113.       case 6:
  114.         nodesArray.sort(sortByDescriptionASC);
  115.         break;
  116.       case 7:
  117.         nodesArray.sort(sortByIssueDESC);
  118.         break;
  119.       case 8:
  120.         nodesArray.sort(sortByIssueASC);
  121.         break;
  122.     }
  123. }
  124.  
  125. function setSorting(value, type) {
  126.     if (sorting == value) {
  127.       sorting = value+1;
  128.     }
  129.     else {
  130.       if (sorting == value+1) {
  131.         sorting = value;
  132.       }
  133.       else {
  134.         sorting = value;
  135.       }
  136.     }
  137.  
  138.     if (type == 1) {
  139.         doSort(localResultNodes);
  140.         var html = getResultHTML(localResultNodes, 1);
  141.         var searchContent = document.getElementById('searchContentLocal');
  142.         if (searchContent != null) {
  143.           searchContent.innerHTML = html;
  144.           resizeIFrame();
  145.           redrawResultsTable();
  146.         }
  147.     }
  148.     else {
  149.         doSort(globalResultNodes);
  150.         var html = getResultHTML(globalResultNodes, type);
  151.         var searchContent = document.getElementById('searchContentGlobal');
  152.         if (searchContent != null) {
  153.           searchContent.innerHTML = html;
  154.           resizeIFrame();
  155.           redrawResultsTable();
  156.         }
  157.     }
  158. }
  159.  
  160. function existsInResults(arrResults, node) {
  161.   var rN = null;
  162.   for (var i=0; i<arrResults.length; i++) {
  163.     rN = arrResults[i];
  164.     if (rN.year == node.year && rN.nr == node.nr && rN.category == node.category && rN.title == node.title && rN.description == node.description && rN.link == node.link) {
  165.       return true;
  166.     }
  167.   }
  168.   return false;
  169. }
  170.  
  171. function getResultArray(resultNodes) {
  172.   var issueNode, resultNode;
  173.   var result = new Array();
  174.  
  175.   for (var i=0; i<resultNodes.length; i++) {
  176.     resultNode = resultNodes[i];
  177.  
  178.     if (resultNode.nodeName != 's') {
  179.       resultNode = resultNode.parentNode;
  180.     }
  181.     issueNode = resultNode.parentNode;
  182.     var itemNode = new nodeResultItem();
  183.     itemNode.year = issueNode.getAttribute('year');
  184.     itemNode.nr = issueNode.getAttribute('nr');
  185.     itemNode.category = resultNode.getAttribute('c');
  186.     if (resultNode.getElementsByTagName('t')[0].hasChildNodes) {
  187.        itemNode.title = resultNode.getElementsByTagName('t')[0].firstChild.nodeValue;
  188.     }
  189.     else {
  190.          itemNode.title = '';
  191.     }
  192.     if (resultNode.getElementsByTagName('k')[0].hasChildNodes) {
  193.        itemNode.description = resultNode.getElementsByTagName('k')[0].firstChild.nodeValue;
  194.     }
  195.     else {
  196.          itemNode.description = '';
  197.     }
  198.     if (resultNode.getElementsByTagName('a')[0].hasChildNodes) {
  199.        itemNode.link = resultNode.getElementsByTagName('a')[0].firstChild.nodeValue;
  200.     }
  201.     else {
  202.          itemNode.link = '';
  203.     }
  204.     if (!existsInResults(result, itemNode)) {
  205.       result.push(itemNode);
  206.     }
  207.   }
  208.   return result;
  209. }
  210.  
  211. function getResultHTML(resultItems, type) {
  212.   var resultNode, issueNode, category, title, description, link, year, nr, issueText, aStart, aEnd;
  213.   var color;
  214.   var imgTitle = '';
  215.   var imgCategory = '';
  216.   var imgDescription = '';
  217.   var imgIssue = '';
  218.     
  219.     /* anpassen !!! */
  220.     var actYear = 2008;
  221.     var actNo = 9;
  222.  
  223.   switch (sorting) {
  224.     case 1:
  225.       imgTitle = '<img src="images/arrows/arrowDown.gif" width="17" height="13" />';
  226.       break;
  227.     case 2:
  228.       imgTitle = '<img src="images/arrows/arrowUp.gif" width="17" height="13"  />';
  229.       break;
  230.     case 3:
  231.       imgCategory = '<img src="images/arrows/arrowDown.gif" width="17" height="13" />';
  232.       break;
  233.     case 4:
  234.       imgCategory = '<img src="images/arrows/arrowUp.gif" width="17" height="13" />';
  235.       break;
  236.     case 5:
  237.       imgDescription = '<img src="images/arrows/arrowDown.gif" width="17" height="13" />';
  238.       break;
  239.     case 6:
  240.       imgDescription = '<img src="images/arrows/arrowUp.gif" width="17" height="13" />';
  241.       break;
  242.     case 7:
  243.       imgIssue = '<img src="images/arrows/arrowDown.gif" width="17" height="13" />';
  244.       break;
  245.     case 8:
  246.       imgIssue = '<img src="images/arrows/arrowUp.gif" width="17" height="13" />';
  247.       break;
  248.   }
  249.  
  250.   doSort(resultItems);
  251.  
  252.   var result = '<div>';
  253.  
  254.   if( resultItems.length > 0 ) {
  255.  
  256.       result += '<table border="0" cellspacing="0" cellpadding="0" width="100%" class="searchResultsTableHeader">';
  257.       result += '<tr id="searchHeader">';
  258.  
  259.       result += '<td id="firstSearchColumn" width="141"><div><a href="javascript: void(0);" style="padding-left: 5px;" onclick="setSorting(1, ' + type + ');">Titel</a></div><div class="sortImage">' + imgTitle + '</div></td>';
  260.       result += '<td id="secondSearchColumn" width="525" class="borderLeft"><div><a href="javascript: void(0);" style="padding-left: 5px;" onclick="setSorting(5, ' + type + ');" class="searchCategory">Beschreibung</a></div><div class="sortImage">' + imgDescription + '</div></td>';
  261.       result += '<td id="thirdSearchColumn" class="right"><div><a href="javascript: void(0);" style="padding-left: 1px;" onclick="setSorting(7, ' + type + ');" class="searchCategory">Ausgabe</a></div><div class="sortImage">' + imgIssue + '</div></td>';
  262.  
  263.       result += '</tr>';
  264.       result += '</table>';
  265.  
  266.       result += '<div style="width: 100%; overflow: auto; background: white;" id="searchResultsDiv"><table cellpadding="0" cellspacing="0" border="0" class="searchResultsTable" id="searchResultsTable">';
  267.  
  268.       var onClickGoTo = "";
  269.             
  270.       for (var i=0; i<resultItems.length; i++) {
  271.         resultItem = resultItems[i];
  272.  
  273.         if (parseInt(resultItem.year) == parseInt(actYear) && parseInt(resultItem.nr) == parseInt(actNo)) {
  274.           issueText = resultItem.year + ' - ' + resultItem.nr;
  275.           
  276.                  aStart = '<a href="javascript: void(0);" onclick="switch_iframe(\'' + resultItem.link + '\');">';
  277.            aEnd = '</a>';
  278.                  
  279.           onClickGoTo = "javascript:switch_iframe('" + resultItem.link + "');";
  280.         }
  281.         else {
  282.           issueText = resultItem.year + ' - ' + resultItem.nr;
  283.           aStart = '';
  284.           aEnd = '';
  285.            onClickGoTo = "";
  286.         }
  287.  
  288.         if (i%2 == 0) {
  289.           color = "One";
  290.         }
  291.         else {
  292.           color = "Two";
  293.         }
  294.  
  295.         result += '<tr valign="top" class="row' + color + '">';
  296.  
  297. //        result += '<td width="130">' + aStart + resultItem.title + aEnd + '</td>';
  298.         if (sorting == 1 || sorting == 2) {
  299.                if (onClickGoTo != '')
  300.                {
  301.                          result += '<td width="130" class="row' + color + 'Sort" onClick="' + onClickGoTo + '" onMouseOver="javascript:hightLightLine( this );" onMouseOut="javascript:unHightLightLine( this );">' + resultItem.title + '</td>';
  302.                         } else {
  303.                         result += '<td width="130" class="row' + color + 'Sort">' + resultItem.title + '</td>';
  304.                         }        
  305.         }
  306.         else {
  307.                  if (onClickGoTo != '')
  308.                    {
  309.                          result += '<td width="130" onClick="' + onClickGoTo + '" onMouseOver="javascript:hightLightLine( this );" onMouseOut="javascript:unHightLightLine( this );">' + resultItem.title + '</td>';
  310.                           } else {
  311.                             result += '<td width="130" >' + resultItem.title + '</td>';
  312.                             }
  313.             }
  314.  
  315.         var tempTxt = ' ';
  316.         if (resultItem.description.length > 0) {
  317.           var tempTxt = resultItem.description;
  318.         }
  319.          
  320.         if (sorting == 5 || sorting == 6) {         
  321.            if (onClickGoTo != '')
  322.                    {
  323.                          result += '<td width="512" class="borderLeft row' + color + 'Sort" onClick="' + onClickGoTo + '" onMouseOver="javascript:hightLightLine( this );" onMouseOut="javascript:unHightLightLine( this );">' + tempTxt + '</td>';
  324.                          } else {
  325.                          result += '<td width="512" class="borderLeft row' + color + 'Sort">' + tempTxt + '</td>';
  326.                          }
  327.         }
  328.         else {
  329.                  if (onClickGoTo != '')
  330.                    {
  331.                    result += '<td width="512" class="borderLeft" onClick="' + onClickGoTo + '" onMouseOver="javascript:hightLightLine( this );" onMouseOut="javascript:unHightLightLine( this );">' + tempTxt + '</td>';
  332.                    } else {
  333.                          result += '<td width="512" class="borderLeft">' + tempTxt + '</td>';
  334.                          }
  335.         }
  336.  
  337.         if (sorting == 7 || sorting == 8) {
  338.              if (onClickGoTo != '')
  339.                    {
  340.                    result += '<td width="79" class="right row' + color + 'Sort" onClick="' + onClickGoTo + '" onMouseOver="javascript:hightLightLine( this );" onMouseOut="javascript:unHightLightLine( this );">' + issueText.replace(/ /g, "").replace(/-/g, "/") + '</td>';
  341.                        } else {
  342.                              result += '<td width="79" class="right row' + color + 'Sort">' + issueText.replace(/ /g, "").replace(/-/g, "/") + '</td>';
  343.                              }
  344.         }
  345.         else {
  346.              if (onClickGoTo != '')
  347.                    {
  348.           result += '<td width="79" class="right" onClick="' + onClickGoTo + '" onMouseOver="javascript:hightLightLine( this );" onMouseOut="javascript:unHightLightLine( this );">' + issueText.replace(/ /g, "").replace(/-/g, "/") + '</td>';
  349.           } else {
  350.                 result += '<td width="79" class="right">' + issueText.replace(/ /g, "").replace(/-/g, "/") + '</td>';
  351.                 }
  352.         }
  353.  
  354.         result += '</tr>';
  355.       }
  356.  
  357.       result += '</table>';
  358.  
  359.   } else {
  360.       result += '<br /><br /><br /><h3 class="searchResults">Keine Elemente gefunden</h3>';
  361.   }
  362.  
  363.   result += '</div>';
  364.  
  365.   return result;
  366. }
  367.  
  368. /**
  369.  * executeInnerHTMLJavaScript
  370.  *
  371.  * @param {Element} element
  372.  */
  373.  function executeInnerHTMLJavaScript( element ) {
  374.  
  375.      if( element != null ) {
  376.  
  377.          var scriptTags = element.getElementsByTagName( "script" );
  378.  
  379.          if( scriptTags != null && scriptTags.length > 0 ) {
  380.  
  381.              for( var loop = 0; loop < scriptTags.length; loop++ ) {
  382.                  eval( scriptTags[loop].text );
  383.              }
  384.          }
  385.      }
  386.  }
  387.  
  388.  function setAllTableCells(parentRow, className) {
  389.    var cells = parentRow.getElementsByTagName('td');
  390.    for (i=0; i<cells.length; i++) {
  391.     switch (i) {
  392.       case 0:
  393.         globalHightLightColor1 = cells[0].className;
  394.         break;
  395.       case 1:
  396.         globalHightLightColor2 = cells[1].className;
  397.         break;
  398.       case 2:
  399.         globalHightLightColor3 = cells[2].className;
  400.         break;
  401.     }
  402.      
  403.      cells[i].className = className;
  404.    }
  405.  }
  406.  
  407.  function restorAllTableCells(parentRow) {
  408.    var cells = parentRow.getElementsByTagName('td');
  409.    for (i=0; i<cells.length; i++) {
  410.     switch (i) {
  411.       case 0:
  412.         cells[0].className = globalHightLightColor1;
  413.         break;
  414.       case 1:
  415.         cells[1].className = globalHightLightColor2;
  416.         break;
  417.       case 2:
  418.         cells[2].className = globalHightLightColor3;
  419.         break;
  420.     }
  421.    }
  422.  }
  423.  
  424. /**
  425.  * hightLightLine
  426.  *
  427.  * @param {Node} element
  428.  */
  429.  function hightLightLine(element) {
  430.      if( element != null ) {
  431.          var parentElement = element.parentNode;
  432.  
  433.          if( parentElement != null ) {
  434.              setAllTableCells(parentElement, 'rowSortActive');
  435.              globalHightLightColor = parentElement.className;
  436.              parentElement.className = "rowActive";
  437.          }
  438.      }
  439.  }
  440.  
  441. /**
  442.  * unHightLightLine
  443.  *
  444.  * @param {Node} element
  445.  */
  446.  function unHightLightLine(element) {
  447.      if( element != null ) {
  448.          var parentElement = element.parentNode;
  449.  
  450.          if( parentElement != null ) {
  451.              restorAllTableCells(parentElement);
  452.              parentElement.className = globalHightLightColor;
  453.          }
  454.      }
  455.  }
  456.  
  457. /**
  458.  * redrawResultsTable
  459.  */
  460.  function redrawResultsTable() {   
  461.  
  462.      var element = document.getElementById( "searchResultsDiv" );
  463.  
  464.      if( element != null ) {
  465.  
  466.          var elementHeight = element.scrollHeight;
  467.  
  468.          var parentElement = element.parentNode;
  469.  
  470.          if( parentElement != null ) {
  471.  
  472.              var parentHeight = parentElement.scrollHeight;
  473.  
  474.              var firstElement = document.getElementById( "firstSearchColumn" );
  475.              var secondElement = document.getElementById( "secondSearchColumn" );
  476.              var thirdElement = document.getElementById( "thirdSearchColumn" );
  477.  
  478.              var tableElement = document.getElementById( "searchResultsTable" );
  479.  
  480.             //alert( "x: " + elementHeight + " - y: " + parentHeight );
  481.  
  482.              if( elementHeight >= parentHeight ) {
  483.  
  484.                  // scrollbar present
  485.  
  486.                  if( firstElement != null ) {
  487.                      firstElement.style.width = "140px";
  488.                  }
  489.  
  490.                  if( secondElement != null ) {
  491.                      secondElement.style.width = "511px";
  492.                  }
  493.  
  494.                  if( tableElement != null ) {
  495.                      tableElement.style.height = "";
  496.                  }
  497.  
  498.              } else {
  499.  
  500.                  // no scrollbar
  501.  
  502.                  if( firstElement != null ) {
  503.                      firstElement.style.width = "142px";
  504.                  }
  505.  
  506.                  if( secondElement != null ) {
  507.                      secondElement.style.width = "524px";
  508.                  }
  509.  
  510.                  if( tableElement != null ) {
  511.                      tableElement.style.height = "100%";
  512.                  }
  513.  
  514.              }
  515.          }
  516.      }     
  517.  }
  518.  
  519. function closeSearchDivs() {
  520.   switchLocalSearchDiv(false);
  521.   switchGlobalSearchDiv(false);
  522.   
  523.   var searchesBox = document.getElementById( "searchesBox" );
  524.   if( searchesBox != null ) {
  525.       searchesBox.style.display = "block";
  526.   }  
  527. }
  528.  
  529. function switchLocalSearchDiv(doShow) {
  530.   var elementSearch = document.getElementById('localsearch');
  531.   var elementIFrame = document.getElementById('iframe');
  532.   if (elementSearch != null && elementIFrame != null) {
  533.       if (doShow) {
  534.         elementSearch.style.display = 'block';
  535.         elementIFrame.style.display = 'none';
  536.       }
  537.       else {
  538.         elementSearch.style.display = 'none';
  539.         elementIFrame.style.display = 'block';
  540.       }
  541.   }
  542. }
  543.  
  544. function switchGlobalSearchDiv(doShow) {
  545.   var elementSearch = document.getElementById('globalsearch');
  546.   var elementIFrame = document.getElementById('iframe');
  547.   if (elementSearch != null && elementIFrame != null) {
  548.       if (doShow) {
  549.         elementSearch.style.display = 'block';
  550.         elementIFrame.style.display = 'none';
  551.       }
  552.       else {
  553.         elementSearch.style.display = 'none';
  554.         elementIFrame.style.display = 'block';
  555.       }
  556.  
  557.  
  558.       var resultsElement = document.getElementById('globalsearchresult');
  559.  
  560.       if( resultsElement != null ) {
  561.         resultsElement.style.display = "none";
  562.       }
  563.  
  564.   }
  565.  
  566. }
  567.  
  568. function importXML(filename, type) {
  569. // 1 - local
  570. // 2 - global
  571.     var xmlDoc = null;
  572.     if (document.implementation && document.implementation.createDocument) {
  573.         xmlDoc = document.implementation.createDocument("", "", null);
  574.     }
  575.     else if (window.ActiveXObject) {
  576.         xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  577.      }
  578.     else {
  579.         alert('Your browser can\'t handle this script');
  580.         return;
  581.     }
  582.     xmlDoc.load(filename);
  583.     xmlDoc.setProperty("SelectionLanguage", "XPath");
  584.  
  585.     if (type == 1) {
  586.       xmlDocLocal = xmlDoc;
  587.     }
  588.     else {
  589.       xmlDocGlobal = xmlDoc;
  590.     }
  591.  
  592. }
  593.  
  594. function doLocalSearch() {
  595.   var res = '';
  596.  
  597.   var searchText = "";
  598.   var element = document.getElementById('searchinput');
  599.   if (element != null) {
  600.     searchText = element.value;
  601.     searchText = searchText.toLowerCase();
  602.   }
  603.   if (searchText != "") {
  604.     switchLocalSearchDiv(true);
  605.     switchGlobalSearchDiv(false);
  606.  
  607.     if (xmlDocLocal == null) {
  608.       importXML('localsearch.xml', 1);
  609.     }
  610.  
  611.     var xpath = "//t[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] | //k[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] | //l[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] | //la[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] | //os[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')]  | //f[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')] ";
  612.  
  613.     var resultNodes = xmlDocLocal.selectNodes(xpath);
  614.     localResultNodes = getResultArray(resultNodes);
  615.     var html = getResultHTML(localResultNodes, 1);
  616.     var searchContent = document.getElementById('searchContentLocal');
  617.  
  618.     if (searchContent != null) {
  619.       searchContent.innerHTML = html;
  620.       resizeIFrame();
  621.       redrawResultsTable();
  622.       //executeInnerHTMLJavaScript( searchContent );
  623.     }
  624.  
  625.     switchLocalSearchDiv(true);
  626.   }
  627. }
  628.  
  629. function getLanguageString() {
  630.   var res = '';
  631.   var langElement;
  632.  
  633.   langElement = document.getElementById('searchInLangDE');
  634.   if (langElement != null && langElement.checked) {
  635.     res += "./parent::*/la[contains(., 'deutsch')] and ";
  636.   }
  637.   langElement = document.getElementById('searchInLangEN');
  638.   if (langElement != null && langElement.checked) {
  639.     res += "./parent::*/la[contains(., 'englisch')] and ";
  640.   }
  641.   langElement = document.getElementById('searchInLangFR');
  642.   if (langElement != null && langElement.checked) {
  643.     res += "./parent::*/la[contains(., 'franz├╢sisch')] and ";
  644.   }
  645.   langElement = document.getElementById('searchInLangES');
  646.   if (langElement != null && langElement.checked) {
  647.     res += "./parent::*/la[contains(., 'spanisch')] and ";
  648.   }
  649.   langElement = document.getElementById('searchInLangIT');
  650.   if (langElement != null && langElement.checked) {
  651.     res += "./parent::*/la[contains(., 'italienisch')] and ";
  652.   }
  653.  
  654.   res = res.substr(0, res.length-4);
  655.  
  656.   if (res != '') {
  657.     res = "((" + res + ") or ./parent::*/la[contains(., 'multilingual')])";
  658.   }
  659.   return res;
  660. }
  661.  
  662. function getOSString() {
  663.   var res = '';
  664.   var osElement;
  665.  
  666.   osElement = document.getElementById('searchInOS95');
  667.   if (osElement != null && osElement.checked) {
  668.     res += "./parent::*/os[contains(., 'Windows 95')] and ";
  669.   }
  670.   osElement = document.getElementById('searchInOS98');
  671.   if (osElement != null && osElement.checked) {
  672.     res += "./parent::*/os[contains(., 'Windows 98')] and ";
  673.   }
  674.   osElement = document.getElementById('searchInOSMe');
  675.   if (osElement != null && osElement.checked) {
  676.     res += "./parent::*/os[contains(., 'Windows Me')] and ";
  677.   }
  678.   osElement = document.getElementById('searchInOS2000');
  679.   if (osElement != null && osElement.checked) {
  680.     res += "./parent::*/os[contains(., 'Windows 2000')] and ";
  681.   }
  682.   osElement = document.getElementById('searchInOS2003');
  683.   if (osElement != null && osElement.checked) {
  684.     res += "./parent::*/os[contains(., 'Windows 2003')] and ";
  685.   }
  686.   osElement = document.getElementById('searchInOSXP');
  687.   if (osElement != null && osElement.checked) {
  688.     res += "./parent::*/os[contains(., 'Windows XP')] and ";
  689.   }
  690.   osElement = document.getElementById('searchInOSXP64');
  691.   if (osElement != null && osElement.checked) {
  692.     res += "./parent::*/os[contains(., 'Windows XP 64')] and ";
  693.   }
  694.   osElement = document.getElementById('searchInOSVista');
  695.   if (osElement != null && osElement.checked) {
  696.     res += "./parent::*/os[contains(., 'Windows Vista')] and ";
  697.   }
  698.   osElement = document.getElementById('searchInOSVista64');
  699.   if (osElement != null && osElement.checked) {
  700.     res += "./parent::*/os[contains(., 'Windows Vista 64')] and ";
  701.   }
  702.  
  703.   res = res.substr(0, res.length-4);
  704.  
  705.   if (res != '') {
  706.     res = "(" + res + ")";
  707.   }
  708.   return res;
  709. }
  710.  
  711. function getGlobalXPathString(searchText) {
  712.   var categoryString = '';
  713.   var res = '';
  714.  
  715.   searchText = searchText.toLowerCase();
  716.  
  717.   // Kategorien
  718.   var catElement = document.getElementById('categoryAll');
  719.   if (catElement != null && !catElement.checked) {
  720.     for (var i=0; i<availableCategories.length; i++) {
  721.       catElement = document.getElementById('category' + i);
  722.       if (catElement != null && catElement.checked) {
  723.         categoryString += "./parent::*[@c='" + availableCategories[i] + "'] or ";
  724.       }
  725.     }
  726.     if (categoryString != '') {
  727.       categoryString = categoryString.substr(0, categoryString.length-3);
  728.       categoryString = "(" + categoryString + ")";
  729.     }
  730.   }
  731.  
  732.   // Sprachen
  733.   var languageString = getLanguageString();
  734.  
  735.   // Betriebsysteme
  736.   var osString = getOSString();
  737.  
  738. //  alert(languageString);
  739.  
  740.   // Ausgaben
  741.   var issueString = '';
  742.   for (var i=0; i<availableIssues.length; i++) {
  743.     var issue = availableIssues[i];
  744.     var year = issue.year;
  745.     var nos = issue.nos;
  746.     var issueElement = document.getElementById('issueyear' + year);
  747.     if (issueElement != null) {
  748.       if (issueElement.checked) {
  749.         // ganzes Jahr
  750.         issueString += "./parent::*/parent::*[@year='" + year + "'] or ";
  751.       }
  752.       else {
  753.         for (var j=0; j<nos.length; j++) {
  754.           var nr = nos[j];
  755.           var issueSubElement = document.getElementById('issueno' + nr + year);
  756.           if (issueSubElement != null && issueSubElement.checked) {
  757.             issueString += "./parent::*/parent::*[@year='" + year + "' and @nr='" + nr + "'] or ";
  758.           }
  759.         }
  760.       }
  761.     }
  762.   }
  763.   if (issueString != '') {
  764.     issueString = issueString.substr(0, issueString.length-3); // -3 damit " or" gefilter wird
  765.     issueString = "(" + issueString + ")";
  766.   }
  767.  
  768.   // im Titel immer suchen
  769.   res += "//t[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')";
  770.   if (categoryString != '') {
  771.     res += " and " + categoryString;
  772.   }
  773.   if (issueString != '') {
  774.     res += " and " + issueString;
  775.   }
  776.   if (languageString != '') {
  777.     res += " and " + languageString;
  778.   }
  779.   if (osString != '') {
  780.     res += " and " + osString;
  781.   }
  782.  
  783.   res += '] | ';
  784.  
  785.   if (document.getElementById('searchInShort').checked) {
  786.       res += "//k[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')";
  787.       if (categoryString != '') {
  788.         res += " and " + categoryString;
  789.       }
  790.       if (issueString != '') {
  791.         res += " and " + issueString;
  792.       }
  793.       if (languageString != '') {
  794.         res += " and " + languageString;
  795.       }
  796.       if (osString != '') {
  797.         res += " and " + osString;
  798.       }
  799.       res += '] | ';
  800.   }
  801.  
  802.   if (document.getElementById('searchInLong').checked) {
  803.       res += "//l[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')";
  804.       if (categoryString != '') {
  805.         res += " and " + categoryString;
  806.       }
  807.       if (issueString != '') {
  808.         res += " and " + issueString;
  809.       }
  810.       if (languageString != '') {
  811.         res += " and " + languageString;
  812.       }
  813.       if (osString != '') {
  814.         res += " and " + osString;
  815.       }
  816.       res += '] | ';
  817.   }
  818.  
  819.   if (document.getElementById('searchInFiles').checked) {
  820.       res += "//f[contains(translate(., '" + bigLetters + "','" + smallLetters + "'),'" + searchText + "')";
  821.       if (categoryString != '') {
  822.         res += " and " + categoryString;
  823.       }
  824.       if (issueString != '') {
  825.         res += " and " + issueString;
  826.       }
  827.       if (languageString != '') {
  828.         res += " and " + languageString;
  829.       }
  830.       if (osString != '') {
  831.         res += " and " + osString;
  832.       }
  833.       res += '] | ';
  834.   }
  835.  
  836.   res = res.substr(0, res.length-2);
  837.  
  838.   return res;
  839. }
  840.  
  841. function searchGlobal_nohistory() {
  842.   var searchText = "";
  843.   var element = document.getElementById('searchglobalinput');
  844.   if (element != null) {
  845.     searchText = element.value;
  846.   }
  847.  
  848.   if (searchText != "") {
  849.     var xpath = getGlobalXPathString(searchText);
  850.     var resultNodes = xmlDocGlobal.selectNodes(xpath);
  851.     globalResultNodes = getResultArray(resultNodes);
  852.     var html = getResultHTML(globalResultNodes, 2);
  853.     var searchContent = document.getElementById('searchContentGlobal');
  854.     if (searchContent != null) {
  855.       searchContent.innerHTML = html;
  856.     }
  857.  
  858.     var resultsElement = document.getElementById('globalsearchresult');
  859.  
  860.     if( resultsElement != null ) {
  861.         resultsElement.style.display = "inline";
  862.     } 
  863.  
  864.     toggleTab_nohistory(2);
  865.  
  866.     if (searchContent != null) {
  867.       resizeIFrame();
  868.       redrawResultsTable();
  869.     }
  870.  
  871.   }
  872. }
  873.  
  874. function searchGlobal() {
  875.   var searchText = "";
  876.   var element = document.getElementById('searchglobalinput');
  877.   if (element != null) {
  878.     searchText = element.value;
  879.   }
  880.  
  881.   if (searchText != "") {
  882.     var xpath = getGlobalXPathString(searchText);
  883.     var resultNodes = xmlDocGlobal.selectNodes(xpath);
  884.     globalResultNodes = getResultArray(resultNodes);
  885.     var html = getResultHTML(globalResultNodes, 2);
  886.     var searchContent = document.getElementById('searchContentGlobal');
  887.     if (searchContent != null) {
  888.       searchContent.innerHTML = html;
  889.     }
  890.  
  891.     var resultsElement = document.getElementById('globalsearchresult');
  892.  
  893.     if( resultsElement != null ) {
  894.         resultsElement.style.display = "inline";
  895.     } 
  896.  
  897.     toggleTab(2);
  898.  
  899.     if (searchContent != null) {
  900.       resizeIFrame();
  901.       redrawResultsTable();
  902.     }
  903.  
  904.   }
  905. }
  906.  
  907. function showDiv(value, divName) {
  908.   var element = document.getElementById(divName);
  909.   if (element != null) {
  910.     if (value) {
  911.       element.style.display = 'block';
  912.     }
  913.     else {
  914.       element.style.display = 'none';
  915.     }
  916.   }
  917. }
  918.  
  919. function showPlaeseWait(value) {
  920.   showDiv(value, 'pleaseWait');
  921. }
  922.  
  923. function showCategoriesDiv(value) {
  924.   showDiv(value, 'searchCategories');
  925. }
  926.  
  927. function showIssuesDiv(value) {
  928.   showDiv(value, 'searchIssues');
  929. }
  930.  
  931. function insertCategoryIntoArray(category) {
  932.   var boolFound = false;
  933.   for (var i=0; i<availableCategories.length; i++) {
  934.     if (availableCategories[i] == category) {
  935.       boolFound = true;
  936.       break;
  937.     }
  938.   }
  939.  
  940.   if (!boolFound) {
  941.     availableCategories.push(category);
  942.   }
  943. }
  944.  
  945. function loadCategories() {
  946.   availableCategories = new Array();
  947.   var category;
  948.   var softwareNodes = xmlDocGlobal.getElementsByTagName('s');
  949.   for (var i=0; i<softwareNodes.length; i++) {
  950.     var softwareNode = softwareNodes[i];
  951.     category = softwareNode.getAttribute('l');
  952.  
  953.     if( category != null && category != "null" ) {
  954.     insertCategoryIntoArray(category);
  955.     }
  956.   }
  957.   availableCategories.sort();
  958. }
  959.  
  960. function insertIssueIntoArray(issueYear, issueNo) {
  961.   var boolFoundYear = false;
  962.   var boolFoundNo = false;
  963.   for (var i=0; i<availableIssues.length; i++) {
  964.     if (availableIssues[i].year == issueYear) {
  965.       boolFoundYear = true;
  966.       for (var j=0; j<availableIssues[i].nos.length; j++) {
  967.         if (availableIssues[i].nos[j] == issueNo) {
  968.           boolFoundNo = true;
  969.           break;
  970.         }
  971.       }
  972.       break;
  973.     }
  974.   }
  975.  
  976.   if (!boolFoundYear) {
  977.     var item = new issueItem();
  978.     item.year = issueYear;
  979.     if (item.nos == null) {
  980.       item.nos = new Array();
  981.     }
  982.     item.nos.push(issueNo);
  983.     availableIssues.push(item);
  984.   }
  985.   else {
  986.     if (!boolFoundNo) {
  987.       var item = availableIssues[i];
  988.       item.nos.push(issueNo);
  989.     }
  990.   }
  991. }
  992.  
  993. function toggleYear(year) {
  994.   var element = document.getElementById('year' + year);
  995.   var elementImage = document.getElementById('plusminus' + year);
  996.   if (element != null) {
  997.     if (element.style.display == 'block') {
  998.       element.style.display = 'none';
  999.       elementImage.src = 'images/tree_plus.gif';
  1000.     }
  1001.     else {
  1002.       element.style.display = 'block';
  1003.       elementImage.src = 'images/tree_minus.gif';
  1004.     }
  1005.   }
  1006. }
  1007.  
  1008. function loadIssues() {
  1009.   availableIssues = new Array();
  1010.   var issueYear;
  1011.   var issueNo;
  1012.   var issueNodes = xmlDocGlobal.getElementsByTagName('i');
  1013.   for (var i=0; i<issueNodes.length; i++) {
  1014.     var issueNode = issueNodes[i];
  1015.     issueYear = issueNode.getAttribute('year');
  1016.     issueNo = issueNode.getAttribute('nr');
  1017.     insertIssueIntoArray(issueYear, issueNo);
  1018.   }
  1019.   availableCategories.sort();
  1020. }
  1021.  
  1022. function uncheckFirstAllCategory(element) {
  1023.   if (element.checked) {
  1024.     var catAll = document.getElementById('categoryAll');
  1025.     if (catAll != null) {
  1026.       catAll.checked = false;
  1027.     }
  1028.   }
  1029. }
  1030.  
  1031. function uncheckCategories(element) {
  1032.   if (element.checked) {
  1033.     for (var i=0; i<availableCategories.length; i++) {
  1034.         var cat = document.getElementById('category' + i);
  1035.         if (cat != null) {
  1036.           cat.checked = false;
  1037.         }
  1038.     }
  1039.   }
  1040. }
  1041.  
  1042. function setCategoriesHTML() {
  1043.   var element = document.getElementById('searchCategories');
  1044.   if (element != null) {
  1045.     var result = '<strong>Lizenzart ausw├ñhlen</strong><br /><br />';
  1046.     result += '<input type="checkbox" id="categoryAll" onclick="uncheckCategories(this);" checked/>Alle<br>';
  1047.     for (var i=0; i<availableCategories.length; i++) {
  1048.       if (availableCategories[i] != '') {
  1049.         result += '<input type="checkbox" id="category' + i + '" onclick="uncheckFirstAllCategory(this);" />' + availableCategories[i] + '<br />';
  1050.       }
  1051.     }
  1052.     element.innerHTML = result;
  1053.   }
  1054. }
  1055.  
  1056. function selectWholeYear(element) {
  1057.   if (element.checked) {
  1058.     var id = element.id;
  1059.     id = id.substr(9);
  1060.     for (var i=0; i<availableIssues.length; i++) {
  1061.       var issue = availableIssues[i];
  1062.       var year = issue.year;
  1063.       var nos = issue.nos;
  1064.       if (year == id) {
  1065.         for (var j=0; j<nos.length; j++) {
  1066.           var tmp = document.getElementById('issueno' + nos[j] + year);
  1067.           tmp.checked = true;
  1068.         }
  1069.       }
  1070.     }
  1071.   }
  1072. }
  1073.  
  1074. function deselectYear(element, year) {
  1075.   if (!element.checked) {
  1076.     var tmp = document.getElementById('issueyear' + year);
  1077.     if (tmp != null) {
  1078.       tmp.checked = false;
  1079.     }
  1080.   }
  1081. }
  1082.  
  1083. function setIssuesHTML() {
  1084.   var issueNoChecked = '';
  1085.   var element = document.getElementById('searchIssues');
  1086.   if (element != null) {
  1087.     var result = '<strong>Ausgaben ausw├ñhlen</strong><br /><br />';
  1088.     for (var i=0; i<availableIssues.length; i++) {
  1089.       var issue = availableIssues[i];
  1090.       var year = issue.year;
  1091.       var nos = issue.nos;
  1092.       var srcLevel1 = 'images/tree_vert_hor.gif';
  1093.       var srcLevel1Next = 'images/tree_vert.gif';
  1094.       if (i == (availableIssues.length-1)) {
  1095.         srcLevel1 = 'images/tree_vert_hor_end.gif';
  1096.         srcLevel1Next = 'images/blank.gif';
  1097.       }
  1098.  
  1099.       result += '<div class="treeview"><img src="' + srcLevel1 + '" /><a href="javascript: void(0);" onclick="toggleYear(\'' + issue.year + '\');"><img src="images/tree_minus.gif" id="plusminus' + issue.year + '" /></a>';
  1100.       result += '<div class="treeContainer"><input class="treeinput" type="checkbox" id="issueyear' + issue.year + '" onclick="selectWholeYear(this);" /><span class="treeline"> ' + year + '</span></div><div class="clearDiv"></div>';
  1101.       result += '<div id="year' + issue.year+ '" style="display: block;">';
  1102.       for (var j=0; j<nos.length; j++) {
  1103.         var srcLevel2 = 'images/tree_vert_hor.gif';
  1104.         if (j == (nos.length-1)) {
  1105.           srcLevel2 = 'images/tree_vert_hor_end.gif';
  1106.         }
  1107.         debug(year + '-' + actYear);
  1108.         debug(nos[j] + '-' + actNo);
  1109.         if (parseInt(year) == parseInt(actYear) && parseInt(nos[j]) == parseInt(actNo)) {
  1110.           issueNoChecked = 'CHECKED';
  1111.         }
  1112.         result += '<div class="treeview"><img src="' + srcLevel1Next + '"><img src="' + srcLevel2 + '"><input class="treeinput" type="checkbox" id="issueno' + nos[j] + year + '" onclick="deselectYear(this, \'' + year + '\');" ' + issueNoChecked + '/><span class="treeline"> ' + nos[j] + '</span></div><div class="clearDiv"></div>';
  1113.       }
  1114.       result += '</div>';
  1115.     }
  1116.  
  1117.     element.innerHTML = result;
  1118.   }
  1119. }
  1120.  
  1121. function doGlobalSearch_nohistory() {
  1122.   var element = document.getElementById('searchglobalinput');
  1123.  
  1124.   var searchesBox = document.getElementById( "searchesBox" );
  1125.  
  1126.   if( searchesBox != null ) {
  1127.       searchesBox.style.display = "none";
  1128.   }
  1129.  
  1130.   if (element != null) {
  1131.     element.value = '';
  1132.   }
  1133.   
  1134.   toggleTab_nohistory(1);
  1135.     
  1136.   var tabResult = document.getElementById('searchContentGlobal');
  1137.   tabResult.innerHTML = '';
  1138.  
  1139.   switchLocalSearchDiv(false);
  1140.   switchGlobalSearchDiv(true);
  1141.   if (xmlDocGlobal == null) {
  1142.     showPlaeseWait(true);
  1143.     importXML('globalsearch.xml', 2);
  1144.     loadCategories();
  1145.     loadIssues();
  1146.     showPlaeseWait(false);
  1147.     if (availableCategories.length > 0) {
  1148.       setCategoriesHTML();
  1149.       showCategoriesDiv(true);
  1150.     }
  1151.     else {
  1152.       showCategoriesDiv(false);
  1153.     }
  1154.     if (availableIssues.length > 0) {
  1155.       setIssuesHTML();
  1156.       showIssuesDiv(true);
  1157.     }
  1158.     else {
  1159.       showIssuesDiv(false);
  1160.     }
  1161.   }
  1162. }
  1163.  
  1164. function doGlobalSearch() {
  1165.   var element = document.getElementById('searchglobalinput');
  1166.  
  1167.   var searchesBox = document.getElementById( "searchesBox" );
  1168.  
  1169.   if( searchesBox != null ) {
  1170.       searchesBox.style.display = "none";
  1171.   }
  1172.  
  1173.   if (element != null) {
  1174.     element.value = '';
  1175.   }
  1176.   
  1177.   toggleTab(1);
  1178.     
  1179.   var tabResult = document.getElementById('searchContentGlobal');
  1180.   tabResult.innerHTML = '';
  1181.  
  1182.   switchLocalSearchDiv(false);
  1183.   switchGlobalSearchDiv(true);
  1184.   if (xmlDocGlobal == null) {
  1185.     showPlaeseWait(true);
  1186.     importXML('globalsearch.xml', 2);
  1187.     loadCategories();
  1188.     loadIssues();
  1189.     showPlaeseWait(false);
  1190.     if (availableCategories.length > 0) {
  1191.       setCategoriesHTML();
  1192.       showCategoriesDiv(true);
  1193.     }
  1194.     else {
  1195.       showCategoriesDiv(false);
  1196.     }
  1197.     if (availableIssues.length > 0) {
  1198.       setIssuesHTML();
  1199.       showIssuesDiv(true);
  1200.     }
  1201.     else {
  1202.       showIssuesDiv(false);
  1203.     }
  1204.   }
  1205. }
  1206.